package com.linhngua.code.gwt.client.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class LimitedSizeList<E> extends ArrayList<E> implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private int limitedSize;

	private Queue<E> queue;

	public LimitedSizeList(){
		
	}
	public LimitedSizeList(int limit) {
		queue = new LinkedList<E>();
		limitedSize = limit;
	}

	public boolean add(E e) {
		queue.add(e);

		super.add(e);
		if (size() > limitedSize) {
			super.remove(queue.poll());
		}

		return true;
	};

}
